#include "../headers/SyntaxAnalysis.h"
#include "../headers/Code_Generator.h"
#include <string>
#include <fstream>
#include <iostream>
#include <stdio.h>

using namespace std;

int test_Translate1(void)
{
	int res=1;
        SyntaxAnalysis *SA=SyntaxAnalysis::Instance();
	string get=SA->Translate("<");
	if(get=="MOVE_LEFT"){
		res=0;
	}
	SA->kill();	
	return  res;
}

int test_Translate2(void)
{
	int res=1;
        SyntaxAnalysis *SA=SyntaxAnalysis::Instance();
	string get=SA->Translate(">");
	
	if(get=="MOVE_RIGHT"){
		res=0;
	}
	SA->kill();	
	return  res;
}

int test_Translate3(void)
{
	int res=1;
        Code_Generator *CG=Code_Generator::Instance();
	string get=CG->Translate("MOVE_RIGHT 6");
	if(get=="\n x+= 6;"){
		res=0;
	}
	CG->kill();	
	return  res;
}



int main()
{
	int test=test_Translate1();
	test+=test_Translate2();
	test+=test_Translate3();

	if(test!=0){
	       	cout << "\nunit test failed";
	}else{
		 FILE *in;
		#ifdef _WIN32 
		  cout<< "WIN32 is defined" << endl;
		  in=_popen("g++ ../cpp/* -O3 -o ../program","r");
		#else
		  cout<< "WIN32 is NOT defined" << endl;
		  in=popen("g++ ../cpp/* -O3 -o ../program","r");
		#endif
	}
	ofstream file;
	file.open("test.txt");
	file << test;
//	file << "\n";
//	file << test1;
	file.close();
return 0;
}
